import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { setStorage, getStorage, hasStorage } from '@/utils/storage'
import getPageTitle from '@/utils/get-page-title'

NProgress.configure({ showSpinner: false }) // NProgress Configuration

const whiteList = ['/login', '/auth-redirect'] // no redirect whitelist

router.beforeEach(async (to, from, next) => {
  // console.log("to>>>>>>>>>>>>>>>", to)
  // console.log("from>>>>>>>>>>>>>>>", from)
  if (to.path === '/login') {
    // NProgress.start()
    // next()
    next({
      path: "/"
    })
  } else {
    // localStorage.getItem('token') == null
    //   ? next({
    //       path: '/login',
    //       query: { redirect: to.fullPath }, // 将跳转的路由path作为参数，登陆成功后跳转到该路由
    //     })
    //   : next()
    next()
  }
})

router.afterEach((to, from) => {
  // console.log("to2222222>>>>>>>>>>>>>>>", to)
  // console.log("from22222222>>>>>>>>>>>>>>>", from)
  // if (to.path === '/homePage') {
  //   router.push({ name: '/task' });
  //   router.push({ path: '/task' }); 
  // }
  NProgress.done()
})
